home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / cvs < prev    next >
Encoding:
Text File  |  2010-11-16  |  11.5 KB  |  393 lines

  1. # cvs(1) completion
  2.  
  3. have cvs && {
  4. set_prefix()
  5. {
  6.     [ -z ${prefix:-} ] || prefix=${cur%/*}/
  7.     [ -r ${prefix:-}CVS/Entries ] || prefix=""
  8. }
  9.  
  10. get_entries()
  11. {
  12.     local IFS=$'\n'
  13.     [ -r ${prefix:-}CVS/Entries ] && \
  14.     entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
  15. }
  16.  
  17. get_modules()
  18. {
  19.     if [ -n "$prefix" ]; then
  20.         COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
  21.     else
  22.         COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
  23.     fi
  24. }
  25.  
  26. _cvs_commands()
  27. {
  28.     cvs --help-commands 2>&1 | awk '/^(     *|\t)/ { print $1 }'
  29. }
  30.  
  31. _cvs_options()
  32. {
  33.     cvs --help-options 2>&1 | awk '/^(     *|\t)-/ { print $1 }'
  34. }
  35.  
  36. _cvs_command_options()
  37. {
  38.     cvs --help $1 2>&1 | sed -ne 's/^[[:space:]]*\(-[^[:space:]=[]*\).*/\1/p'
  39. }
  40.  
  41. _cvs_kflags()
  42. {
  43.     COMPREPLY=( $( compgen -W 'kv kvl k o b v' -- "$cur" ) )
  44. }
  45.  
  46. _cvs_roots()
  47. {
  48.     local -a cvsroots
  49.     cvsroots=( $CVSROOT )
  50.     [ -r ~/.cvspass ] && \
  51.         cvsroots=( "${cvsroots[@]}" $( awk '{ print $2 }' ~/.cvspass ) )
  52.     [ -r CVS/Root ] && cvsroots=( "${cvsroots[@]}" $(cat CVS/Root) )
  53.     COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) )
  54.     __ltrim_colon_completions "$cur"
  55. }
  56.  
  57. _cvs()
  58. {
  59.     local cur prev count mode i cvsroot cvsroots pwd
  60.     local -a flags miss files entries changed newremoved
  61.  
  62.     COMPREPLY=()
  63.     _get_comp_words_by_ref -n : cur prev
  64.  
  65.     count=0
  66.     for i in "${COMP_WORDS[@]}"; do
  67.         [ $count -eq $COMP_CWORD ] && break
  68.         # Last parameter was the CVSROOT, now go back to mode selection
  69.         if [[ "${COMP_WORDS[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
  70.             mode=""
  71.         fi
  72.         if [ -z "$mode" ]; then
  73.             case $i in
  74.                 -H|--help)
  75.                     COMPREPLY=( $( compgen -W "$( _cvs_commands )" -- "$cur" ) )
  76.                     return 0
  77.                     ;;
  78.                 -d)
  79.                     mode=cvsroot
  80.                     cvsroot=${COMP_WORDS[((count+1))]}
  81.                     ;;
  82.                 ad|add|new)
  83.                     mode=add
  84.                     ;;
  85.                 adm|admin|rcs)
  86.                     mode=admin
  87.                     ;;
  88.                 ann|annotate)
  89.                     mode=annotate
  90.                     ;;
  91.                 checkout|co|get)
  92.                     mode=checkout
  93.                     ;;
  94.                 com|commit|ci)
  95.                     mode=commit
  96.                     ;;
  97.                 di|dif|diff)
  98.                     mode=diff
  99.                     ;;
  100.                 ex|exp|export)
  101.                     mode=export
  102.                     ;;
  103.                 edit|unedit)
  104.                     mode=$i
  105.                     ;;
  106.                 hi|his|history)
  107.                     mode=history
  108.                     ;;
  109.                 im|imp|import)
  110.                     mode=import
  111.                     ;;
  112.                 re|rel|release)
  113.                     mode=release
  114.                     ;;
  115.                 log|rlog)
  116.                     mode=log
  117.                     ;;
  118.                 rdiff|patch)
  119.                     mode=rdiff
  120.                     ;;
  121.                 remove|rm|delete)
  122.                     mode=remove
  123.                     ;;
  124.                 rtag|rfreeze)
  125.                     mode=rtag
  126.                     ;;
  127.                 st|stat|status)
  128.                     mode=status
  129.                     ;;
  130.                 tag|freeze)
  131.                     mode=tag
  132.                     ;;
  133.                 up|upd|update)
  134.                     mode=update
  135.                     ;;
  136.             esac
  137.         elif [[ "$i" = -* ]]; then
  138.             flags=( "${flags[@]}" $i )
  139.         fi
  140.         count=$((++count))
  141.     done
  142.  
  143.     case $mode in
  144.         add)
  145.             case $prev in
  146.                 -m)
  147.                     return 0
  148.                     ;;
  149.                 -k)
  150.                     _cvs_kflags
  151.                     return 0
  152.                     ;;
  153.             esac
  154.  
  155.             if [[ "$cur" != -* ]]; then
  156.                 set_prefix
  157.                 if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
  158.                     get_entries
  159.                     [ -z "$cur" ] && \
  160.                     files=$( command ls -Ad !(CVS) ) || \
  161.                     files=$( command ls -d ${cur}* 2>/dev/null )
  162.                     for i in "${entries[@]}"; do
  163.                         files=( ${files[@]/#$i//} )
  164.                     done
  165.                     COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) )
  166.                 fi
  167.             else
  168.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  169.                     -- "$cur" ) )
  170.             fi
  171.             ;;
  172.         admin)
  173.             case $prev in
  174.                 -a|-A|-b|-c|-e|-l|-m|-n|-N|-o|-s|-t-|-u)
  175.                     return 0
  176.                     ;;
  177.                 -t)
  178.                     _filedir
  179.                     return 0
  180.                     ;;
  181.                 -k)
  182.                     _cvs_kflags
  183.                     return 0
  184.                     ;;
  185.             esac
  186.  
  187.             if [[ "$cur" = -* ]]; then
  188.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  189.                     -- "$cur" ) )
  190.             fi
  191.             ;;
  192.         annotate)
  193.             [[ "$prev" == -@(r|D) ]] && return 0
  194.  
  195.             if [[ "$cur" = -* ]]; then
  196.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  197.                     -- "$cur" ) )
  198.             else
  199.                 get_entries
  200.                 COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) )
  201.             fi
  202.             ;;
  203.         checkout)
  204.             case $prev in
  205.                 -r|-D|j)
  206.                     return 0
  207.                     ;;
  208.                 -d)
  209.                     _filedir -d
  210.                     return 0
  211.                     ;;
  212.                 -k)
  213.                     _cvs_kflags
  214.                     return 0
  215.                     ;;
  216.             esac
  217.  
  218.             if [[ "$cur" != -* ]]; then
  219.                 [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  220.                 COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
  221.                     awk '{print $1}' ) )
  222.                 COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
  223.             else
  224.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  225.                     -- "$cur" ) )
  226.             fi
  227.             ;;
  228.         commit)
  229.             case $prev in
  230.                 -m|-r)
  231.                     return 0
  232.                     ;;
  233.                 -F)
  234.                     _filedir
  235.                     return 0
  236.                     ;;
  237.             esac
  238.  
  239.             set_prefix
  240.  
  241.             if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then
  242.                 # if $COMP_CVS_REMOTE is not null, 'cvs commit' will
  243.                 # complete on remotely checked-out files (requires
  244.                 # passwordless access to the remote repository
  245.                 if [ -n "${COMP_CVS_REMOTE:-}" ]; then
  246.                     # this is the least computationally intensive
  247.                 # way found so far, but other changes
  248.                 # (something other than changed/removed/new)
  249.                 # may be missing
  250.                 changed=( $( cvs -q diff --brief 2>&1 | \
  251.                 sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
  252.                 newremoved=( $( cvs -q diff --brief 2>&1 | \
  253.                 sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
  254.                 COMPREPLY=( $( compgen -W '${changed[@]:-} \
  255.                            ${newremoved[@]:-}' -- "$cur" ) )
  256.                 else
  257.                     COMPREPLY=( $(compgen -o default -- "$cur") )
  258.                 fi
  259.             else
  260.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  261.                     -- "$cur" ) )
  262.             fi
  263.             ;;
  264.         cvsroot)
  265.             # TODO: works poorly because of the colons and -o default,
  266.             #       could we drop -o default?  works ok without it in cvsps
  267.             _cvs_roots
  268.             ;;
  269.         export)
  270.             case $prev in
  271.                 -r|-D)
  272.                     return 0
  273.                     ;;
  274.                 -d)
  275.                     _filedir -d
  276.                     return 0
  277.                     ;;
  278.                 -k)
  279.                     _cvs_kflags
  280.                     return 0
  281.                     ;;
  282.             esac
  283.  
  284.             if [[ "$cur" != -* ]]; then
  285.                 [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  286.                 COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
  287.                 COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
  288.             else
  289.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  290.                     -- "$cur" ) )
  291.             fi
  292.             ;;
  293.         diff)
  294.             if [[ "$cur" == -* ]]; then
  295.                 _longopt diff
  296.             else
  297.                 get_entries
  298.                 COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) )
  299.             fi
  300.             ;;
  301.         remove)
  302.             if [[ "$cur" != -* ]]; then
  303.                 set_prefix
  304.                 if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
  305.                     get_entries
  306.                     # find out what files are missing
  307.                     for i in "${entries[@]}"; do
  308.                         [ ! -r "$i" ] && miss=( "${miss[@]}" $i )
  309.                     done
  310.                     COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") )
  311.                 fi
  312.             else
  313.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  314.                     -- "$cur" ) )
  315.             fi
  316.             ;;
  317.         import)
  318.             case $prev in
  319.                 -I|-b|-m|-W)
  320.                     return 0
  321.                     ;;
  322.                 -k)
  323.                     _cvs_kflags
  324.                     return 0
  325.                     ;;
  326.             esac
  327.  
  328.             if [[ "$cur" != -* ]]; then
  329.                 # starts with same algorithm as checkout
  330.                 [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  331.                 prefix=${cur%/*}
  332.                 if [ -r ${cvsroot}/${prefix} ]; then
  333.                     get_modules
  334.                     COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
  335.                     COMPREPLY=( ${COMPREPLY[@]#\/} )
  336.                 fi
  337.                 pwd=$( pwd )
  338.                 pwd=${pwd##*/}
  339.                 COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- $cur ) )
  340.             else
  341.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  342.                     -- "$cur" ) )
  343.             fi
  344.             ;;
  345.         update)
  346.             case $prev in
  347.                 -r|-D|-j|-I|-W)
  348.                     return 0
  349.                     ;;
  350.                 -k)
  351.                     _cvs_kflags
  352.                     return 0
  353.                     ;;
  354.             esac
  355.  
  356.             if [[ "$cur" = -* ]]; then
  357.                 COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
  358.                     -- "$cur" ) )
  359.             fi
  360.             ;;
  361.         "")
  362.             case $prev in
  363.                 -T)
  364.                     _filedir -d
  365.                     return 0
  366.                     ;;
  367.                 -e|-s)
  368.                     return 0
  369.                     ;;
  370.                 -z)
  371.                     COMPREPLY=( $( compgen -W '1 2 3 4 5 6 7 8 9' -- "$cur" ) )
  372.                     return 0
  373.                     ;;
  374.             esac
  375.  
  376.             COMPREPLY=( $( compgen -W '$( _cvs_commands ) $( _cvs_options ) \
  377.                 --help --help-commands --help-options --version' -- "$cur" ) )
  378.             ;;
  379.     esac
  380.  
  381.     return 0
  382. }
  383. complete -F _cvs -o default cvs
  384. }
  385.  
  386. # Local variables:
  387. # mode: shell-script
  388. # sh-basic-offset: 4
  389. # sh-indent-comment: t
  390. # indent-tabs-mode: nil
  391. # End:
  392. # ex: ts=4 sw=4 et filetype=sh
  393.